#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

using vec = vector<vector<int>>;

int dfs(vec &gh, int u, int e, vector<int> &path, vector<int> &vis)
{
        if(u == e){
                for(auto v : path){
                        cout << v << " ";
                }
                cout<<endl;
                return 1;
        
        }
        vis[u] = 1;
        int ans = 0;
        for(auto v : gh[u]){
                if(vis[v]){
                        continue;
                }
                path.push_back(v);
                ans += dfs(gh, v, e, path, vis);
                path.pop_back();
        }
        vis[u] = 0;

        return ans;
}

int main()
{
        int n, m;
        cin >> n >> m;

        vec gh(n + 1);
        for(int i = 0; i < m; i++){
                int u, v;
                cin >> u >> v;
                gh[u].push_back(v);
        }        

        vector<int> path;
        vector<int> vis(n + 1, 0);
        cout<<"***************"<<endl;
        path.push_back(1);
        cout << dfs(gh, 1, 4, path, vis) << " ways" <<endl;
        return 0;
}
/*
4 6
1 2
1 3
2 3
3 2
2 4
3 4
*/